const server = require('http').createServer();
const io = require('socket.io')(server, {
  cors: true
});
io.on('connection', client => {
  console.log('clint ---- >');
  console.log(client.id);
  console.log(' sockets ----- >');
  console.log(io.sockets.sockets.keys());
  console.log('handshake --->');
  console.log(client.handshake.headers.authorization);
  client.handshake.headers.authorization = client.id;
  client.emit('news', {
    hello: 'world',
    // clients: t
  });
  console.log('有人连接了');
  client.on('event', data => {
    console.log('event: ', data);
  });
  client.on('otherEvent', data => {
    console.log('my other event: ', data);
  });
  client.on('disconnect', () => {
    console.log('Disconnect');
  });
});

server.listen(3000);
console.log('server started at http://localhost:3000/');